% This is a small tutorial for the usage of this curvelet transformation
% implementation
%
%author: Sebastian Schmelcher version: 2012-02-29

%A very quick example:


img256=double(imread('lena256.pgm'))/255; %256x256 image

img32=sample_down(img256,8); %32x32 image

%Curvelet Transformation

identifier='mycandes';
%which mesh do you want to use? 'mycandes' implements the standart partition of the
%fourier space. Here further implementations (e.g.limited angle
%partitions...) could be used.If you want to add a new partition several functions
%have to be edited. You will find a HowTo at the end of this tutorial.


coef=ct(img32,identifier);

%The coefficients
%
%coef is a cell array containg all the curvelet coefficients in the
%following manner:
%coef{radial}{angular} contains a (n x m) image of all coefficients corresponding 
%to the radial and angular index for radial=1:end-1
%In coef{end} the low pass is stored. E.g. :
% coef = 
% 
%     {  8x1   cell  }  <-- all the coefficient for the first radial scale (not low pass)
%     {  8x1   cell  }
%     { 16x1   cell  }
%     { 16x1   cell  }
%     { 32x1   cell  }
%     { 32x1   cell  }
%     { 64x1   cell  }
%     { 64x1   cell  }
%     {128x1   cell  }  <--- last radial scale (here for a 512x512 image its the 9th scale)
%     [512x512 double]  <--- lowpass

%now one could use tresholding
pctg=.2; % 20 percentage
coef_trsh=coef_approx(coef,pctg); %only pctf of the coefficients are allowed to be non-zero

%Inverse Curvelet Transformation

img_rec=ict(coef,identifier);%recovered image without tresholding
img_trsh=ict(coef_trsh,identifier);%with tresholding




% If you don't want to use the whole fourier domain you can apply a
% fourier mask. This mask is applied directly after the fourier
% transformation. This can e.g. be used for the simulation of a limited angle

window='window30';%This sets the fourier coeficient outside a 30 degree angle to zero
window='window30+';%The + adds the lowpass, the 3x3 center of the fourier domain 
window='window30+r20';%r20 randomly sets 80 percent of the remaining coeficients to zero
%These are functions with a sharp edge in the angular direction. The numbers
%can be changes as long as the number of digits stays the same. If you want
%to have a smooth cut you can use:
window='smooth_lin25_30';
%This represents a linear decay between degree 25 and 30
window='smooth_lin25_30+';
%Adds the lowpass
window='smooth_mey25_30';
%creates a Mayerwindow, e.g. a cosin is used to create a smooth cutting
window='smooth_mey25_30+';
%adds the lowpass

coef_limited=ct(img32,identifier,window);






%%% HOW TO ADD A NEW PARTITION %%%
%
%
%FIRST: Create a function 'curvelet_MYPARTITION.m' with input
%(imSize,radial,angular) where imSize=size(img)=[n,m] and radial,angular
%are the indicies in radial and angular direction (integers).
%
%This function should return a curvelet in fourier domain (e.g. a wedge)
%coresponding to the radial and angular scale.
%
%e.g. function cur=curvelet_MYPARTITION(imSize,radial,angular)
%
%

%Now you have to add information to the following functions:
%
%1. indexStruct=get_indexStruct(identifier,varargin)
%   This function returns an array [a1,a2,a3,...] whrere a1 is the number
%   of angular indicies for the first radial scale, a2 the number of
%   angular indicies for the second radial scale and so on.
%   e.g. for the standart partition it is [8 8 16 16 32 ...]
%   the length of the array represents the number of radial scales.
%   During the curvelet transformation the function will be called with
%   get_indexStruct(identifier,imSize) where imSize=size(img)
%   thus varargin{1}=[n,m].
%
%2. cur=get_curvelet(identifier,imSize,radial,angular)
%   This function calls curvelet_MYPARTITION(imSize,radial,angular).
%   It is just used to call the function corresponding to the identifier



